// 为对象执行方法, 并返回修改后的模型
extension FlatMap<T> on T? {
  E? flatMap<E>(E? Function(T) f) => this != null ? f(this!) : null;
}

extension CompactMap<T, E> on Map<T, E> {
  Iterable<V> compactMap<V>(V? Function(MapEntry<T, E>) f) sync* {
    for (final entry in entries) {
      final extracted = f(entry);
      if (extracted != null) {
        yield extracted;
      }
    }
  }
}

// AuthUser? get insteadOfThis {
//   final user = FirebaseAuth.instance.currentUser;
//   if (user != null) {
//     return AuthUser.fromFirebase(user);
//   } else {
//     return null;
//   }
// }

// AuthUser? get doThis =>
//     FirebaseAuth.instance.currentUser.flatMap((u) => AuthUser.fromFirebase(u));

const foo = 'foo';
const bar = 'bar';
const baz = 'baz';

const namesAndAges = {
  foo: 20,
  bar: 25,
  baz: 18,
};

const acceptedNames = [
  foo,
  bar,
];

void testIt() {
  final acceptedAges = namesAndAges.compactMap(
    (e) => acceptedNames.contains(e.key) ? e.value : null,
  );
  acceptedAges.toList(); // [20, 25]
}
